package com.recruit.wechat.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.recruit.wechat.bean.WechatUser;
import com.recruit.wechat.controller.helper.$;
import com.recruit.wechat.controller.model.ApiResultModel;
import com.recruit.wechat.mapper.WechatUserMapper;
import com.recruit.wechat.service.WechatUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.recruit.wechat.bean.result.ResultPage;

import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 肖守凯
 * @since 2020-08-19
 */
@Service
public class WechatUserServiceImpl extends ServiceImpl<WechatUserMapper, WechatUser> implements WechatUserService {
    /** 添加WechatUser
     * @param wechatUser  前端传进的参数
     * @return 返回统一信息
     */
    @Override
    public ApiResultModel addWechatUser(WechatUser wechatUser  ) {
           if(this.save(wechatUser )){
               return $.success();
           }else{
                return $.error("添加失败");
           }
    }
    /** 编辑跳转页面的回显数据WechatUser
     * @param id  前端传进的参数
     * @return 返回实体类
     */
    @Override
    public WechatUser selectWechatUserByIdWechatUser(Integer id ){
            return this.getById(id);
    }


    /** 编辑WechatUser
     * @param wechatUser  前端传进的参数
     * @return 返回统一信息
     */
    @Override
    public ApiResultModel editWechatUser(WechatUser wechatUser  ) {



           if(this.updateById(wechatUser )){
               return $.success();
           }else{
                return $.error("编辑失败");
           }
    }
    /** 删除一条WechatUser
     * @param id  前端传进的ID
     * @return 返回统一信息
     */
    @Override
    public   ApiResultModel delWechatUser( Integer id  ){
           if(this.removeById(id)){
               return $.success();
           }else{
                return $.error("删除失败");
           }
    }

   /** 分页查询WechatUser
     * @param page  页码
     * @param limit  查几条
     * @param wechatUser  前端传进的参数
     * @return 返回统一分页信息
     */
    @Override
    public  ResultPage findWechatUserByPage(Integer page, Integer limit,WechatUser wechatUser){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", (page - 1) * limit);
        paramMap.put("limit", limit);
        paramMap.put("wechatUser", wechatUser);
        List<WechatUser> list = baseMapper.selectMyPage(paramMap);
        Integer count = baseMapper.countMyPage(paramMap);
        ResultPage<WechatUser> resultPage = new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }

    @Override
    public WechatUser login(String phone, String password) {

        return baseMapper.login(phone, password);



    }

    //查询删除状态为正常0 且 是否为企业0 所有用户集合
    @Override
    public List<WechatUser> getUserListByTrIsDeleteAndTrIsCompany() {
        QueryWrapper<WechatUser> wrapper = new QueryWrapper<WechatUser>();
        wrapper.eq("tr_is_delete",0)
                .eq("tr_is_company",0);
        List<WechatUser> wechatUserList = baseMapper.selectList(wrapper);
        return wechatUserList;
    }
}
